﻿using System;
using System.Collections.Generic;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class FormulaFunction_Backstab : FormulaFunction
    {
        public override EFormulaFunctionType funcType => EFormulaFunctionType.bBackstab;

        public override void Calculate(Stack<IFormulaOperand> rCalopd, IFormulaObject rSelf, IFormulaObject rTarget, Formula rFromFormula)
        {
            if (rSelf != null && rTarget != null && rTarget is Unit rUnit)
            {
                var rType = rUnit.CheckBackstab(rSelf.GetPos() - rTarget.GetPos());
                IFormulaOperand result = FormulaHelper.FetchOperand(EFormulaOperandType.Num);
                result.Set(((int)rType).ToLFloat());
                rCalopd.Push(result);
            }
            else
            {
                throw new Exception($"{funcType} func need two battleUnit");
            }
        }
    }
}